#!/bin/bash
echo "Building cbp2make_ai with MSYS2 UCRT64..."
echo

# 检查是否在 MSYS2 UCRT64 环境中
if [[ ! -f "/etc/msys2-release" ]]; then
    echo "错误: 请在 MSYS2 UCRT64 环境中运行此脚本"
    echo "请从开始菜单启动: MSYS2 UCRT64"
    exit 1
fi

# 检查 wxWidgets 是否已安装
if ! pkg-config --exists wxwidgets; then
    echo "错误: wxWidgets 未安装"
    echo "请运行: pacman -S mingw-w64-ucrt-x86_64-wxWidgets"
    exit 1
fi

# 获取 wxWidgets 信息
echo "wxWidgets 信息:"
pkg-config --modversion wxwidgets
pkg-config --cflags wxwidgets
echo

# 创建构建目录
mkdir -p build
cd build

# 配置 CMake
echo "配置 CMake..."
cmake .. -G "MinGW Makefiles" \
    -DCMAKE_BUILD_TYPE=Release

if [ $? -ne 0 ]; then
    echo "CMake 配置失败!"
    exit 1
fi

# 编译
echo "编译中..."
make -j$(nproc)

if [ $? -ne 0 ]; then
    echo "编译失败!"
    exit 1
fi

cd ..
echo
echo "编译成功!"
echo "可执行文件: build/cbp2make_ai.exe"
echo
